<?php
class DirectoryController extends AppController {
	var $name = 'Directory';
	var $uses = array('Semester', "Assignment", 'Apartement', 'SemesterApartement');

	function index() {
		$this->set('semesters', $this->Semester->findAll());
	}

	function chooseApartement($semesterId = null) {
		if ($semesterId == null) {
			$this->redirect('directory');
			return;
		}

		$this->set('apartements', $this->SemesterApartement->findAllBySemesterId($semesterId));
		$this->set('semesterId', $semesterId);
	}

	function listResidents($semesterId = null, $apartementId = null) {
		if ($semesterId == null && $apartementId == null) {
			$this->redirect('/directory');
			return;
		}

		if ($apartementId == null) {
			$this->redirect("/directory/chooseApartement/$semesterId");
			return;
		}

		$residents = $this->Assignment->findResidents($semesterId, $apartementId);
		$this->set('residents', $residents);
		$this->set('semester', $this->Semester->find($semesterId));
		$this->set('apartement', $this->Apartement->find($apartementId));
	}
}
?>
